package com.cq.hd.app.controller;

import com.cq.hd.common.annotation.LoginUser;
import com.cq.hd.common.entity.AppLoginUser;
import com.cq.hd.common.enums.ResponseEnums;
import com.cq.hd.common.pagination.Page;
import com.cq.hd.common.response.Result;
import com.cq.hd.common.response.Throw;
import com.cq.hd.product.api.TbActiveBrowseApi;
import com.cq.hd.product.api.dto.ActiveBrowsePageDto;
import com.cq.hd.product.api.vo.ActiveBrowsePageVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

@RestController
@RequestMapping("/activeBrowse")
@Api(tags = "活动浏览记录相关接口")
public class ActiveBrowseController {

    @Autowired
    private TbActiveBrowseApi activeBrowseApi;

    @ApiOperation(value = "浏览活动列表")
    @ApiImplicitParam(name = "activeBrowsePageDto", value = "实体", paramType = "query", dataType = "ActiveBrowsePageDto")
    @ApiResponse(response = ActiveBrowsePageVo.class, code = 200, message = "接口返回对象参数")
    @GetMapping("/page")
    public Result<Page<ActiveBrowsePageVo>> page(@ApiIgnore @LoginUser AppLoginUser appLoginUser, ActiveBrowsePageDto activeBrowsePageDto) {
        activeBrowsePageDto.setUserId(appLoginUser.getUserId());
        return activeBrowseApi.page(activeBrowsePageDto);
    }

    @ApiOperation(value = "清空浏览记录")
    @DeleteMapping("/clear")
    public Result<Boolean> clear(@ApiIgnore @LoginUser AppLoginUser appLoginUser) {
        if (appLoginUser == null || appLoginUser.getUserId() == null || appLoginUser.getUserId() <= 0) {
            Throw.isBusinessException(ResponseEnums.USER_ACCESS_DENIED);
        }
        return activeBrowseApi.clear(appLoginUser.getUserId());
    }

}
